@extends('admin.default')
@section('title', '题库列表')
@section('content')
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
                            <button class="layui-btn" onclick="xadmin.open('添加章节','{{route('admin.sections.create',$id->id)}}',600,400)"><i class="layui-icon"></i>添加章节</button>
                        </div>
                        <div class="layui-card-body layui-table-body layui-table-main">
                            <table class="layui-table layui-form" ID="table">
                                <thead>
                                  <tr>
                                    <th>
                                      <input type="checkbox" lay-filter="checkall" name="" lay-skin="primary">
                                    </th>
                                    <th>ID</th>
                                    <th>章节名</th>
                                    <th>所属科目</th>
                                    <th>权重</th>
                                    <th>题目总数</th>
                                    <th>状态</th>
                                    <th>操作</th></tr>
                                </thead>
                                <tbody>
                                @foreach($data as $val)
                                  <tr>
                                    <td>
                                      <input type="checkbox" name="id" value=""   lay-skin="primary">
                                    </td>
                                    <td>{{$val->id}}</td>
                                      <td><a href="javascript:xadmin.add_tab_f('题库','{{route('admin.sections.show',$val->id)}}',true);"><span class="layui-badge layui-badge-green">{{$val->name}}</span></a></td>

                                      <td>{{$id->name}}</td>
                                      <td>{{$val->order}}</td>
                                      <td>100</td>
                                    <td class="td-status">
                                    <span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span>
                                    </td>
                                    <td class="td-manage">



                                        <a title="编辑"  onclick="xadmin.open('编辑','{{route('admin.sections.edit',$val->id)}}',500,300)" href="javascript:;">
                                            <i class="layui-icon">&#xe642;</i>
                                        </a>
                                        <a title="删除" onclick="sections_del('{{$val->id}}','{{route('admin.sections.destroy',$val->id)}}')" href="javascript:;">
                                            <i class="layui-icon">&#xe640;</i>
                                        </a>
                                    </td>
                                  </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                        <div class="layui-card-body ">
                            {{$data->links('admin.question_page') }}

                        </div>
                    </div>
                </div>
            </div>
        <script>
            layui.use(['laydate','form'], function(){
                var laydate = layui.laydate;
                var  form = layui.form;
                form.on('checkbox(checkall)', function(data){
                    if(data.elem.checked){
                        $('tbody input').prop('checked',true);
                    }else{
                        $('tbody input').prop('checked',false);
                    }
                    form.render('checkbox');
                });
                //执行一个laydate实例
                laydate.render({
                    elem: '#start' //指定元素
                });

                //执行一个laydate实例
                laydate.render({
                    elem: '#end' //指定元素
                });


            });
            function sections_del(id,url){
                layer.msg('你确定要删除该问题么？', {
                    time: 0 //不自动关闭
                    ,btn: ['确定', '取消']
                    ,yes: function(index){
                        $.ajax({
                            type: 'POST',
                            url: url,
                            data:{
                                '_token':'{{csrf_token()}}',
                                '_method':'DELETE'
                            },
                            dataType: 'json',
                            success: function (data) {
                                if(data == 1){
                                    layer.alert('删除成功', {
                                        icon: 1,
                                        skin: 'layui-layer-molv' //样式类名
                                        ,closeBtn: 0
                                    }, function(){
                                        window.location.reload();
                                    });
                                } else{
                                    layer.alert('删除失敗', {
                                        icon: 2,
                                        skin: 'layui-layer-molv' //样式类名
                                        ,closeBtn: 0
                                    });
                                }
                            }
                        });
                    }
                });


            }



            /*function delAll (argument) {
                var ids = [];

                // 获取选中的id
                $('tbody input').each(function(index, el) {
                    if($(this).prop('checked')){
                        ids.push($(this).val())
                    }
                });

                layer.confirm('确认要删除吗？'+ids.toString(),function(index){
                    //捉到所有被选中的，发异步进行删除
                    layer.msg('删除成功', {icon: 1});
                    $(".layui-form-checked").not('.header').parents('tr').remove();
                });
            }*/
        </script>
        @stop

